from brispon.models import (Store, Event, Coupon, FavoriteStore, FavoriteCoupon,\
                            Category, Order, SiteUser, Recruit, Logging,\
                            Keyword
                            )
from django.contrib import admin

class OrderAdmin(admin.ModelAdmin):
    list_display = ('name', 'store', 'event', 'mobile', 'price', 'registry')
    search_fields = ['name', 'store', 'event', 'registry']
    class Media:
        js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce/textareas.js')

class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ['name']
    
class StoreAdmin(admin.ModelAdmin):
    list_display = ('name', 'category', 'latitude', 'longitude', 'tags', 'registry')
    search_fields = ['name']
    list_filter = ('category', 'ad_type', 'store_type')
    list_per_page = 15
    fieldsets =((None, {'fields':('category',
                                  'ad_type',
                                  'store_type',
                                  'name',
                                  'enname',
                                  'logo',
                                  'thumbnail',
                                  'representative',
                                  'description',
                                  'extra',
                                  'detail_addr',
                                  'addr',
                                  'tel1',
                                  'tel2',
                                  'internet_tel',
                                  'mobile1',
                                  'mobile2',
                                  'fax',
                                  'kakao',
                                  'email',
                                  'website',
                                  'trading_hours',
                                  'branchs',
                                  'image1',
                                  'image2',
                                  'image3',
                                  'image4',
                                  'image5',
                                  'image6',
                                  'image7',
                                  'image8',
                                  'image9',
                                  'image10',
                                  'tags',
                                  )}),
                ('Extra Information', {'classes': ('extrapretty',),
                          'fields':('tweet',
                                    'like',
                                    'latitude',
                                    'longitude',
                                    )}))
    
    class Media:
        js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce/textareas.js')

class FavoriteStoreAdmin(admin.ModelAdmin):
    list_display = ('user', 'store', 'registry')
    
class EventAdmin(admin.ModelAdmin):
    list_display = ('name', 'store', 'active', 'event_type', 'tags', 'sdate', 'edate', 'registry')
    search_fields = ['name', 'store__name']
    list_filter = ('active', 'event_type')
    list_editable = ('active', 'event_type')
    list_per_page = 15
    fieldsets =((None, {'fields':('store',
                                  'name',
                                  'event_type',
                                  'representative',
                                  'short_description',
                                  'description',
                                  'extra',
                                  'thumbnail',
                                  'sdate',
                                  'edate',
                                  'active',
                                  'detail',
                                  'mainimage',
                                  'sideimage',
                                  'image1',
                                  'image2',
                                  'image3',
                                  'image4',
                                  'image5',
                                  'image6',
                                  'image7',
                                  'image8',
                                  'image9',
                                  'image10',
                                  'tags',
                                  )}),
                ('Extra Information', {'classes': ('extrapretty',),
                          'fields':('tweet',)}))
    
    class Media:
        js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce/textareas.js')


class CouponAdmin(admin.ModelAdmin):
    list_display = ('name', 'start_count', 'current_count', 'event', 'registry')
    list_display_links = ('name', 'event')

class FavoriteCouponAdmin(admin.ModelAdmin):
    list_display = ('user', 'coupon', 'registry')
    
class RecruitAdmin(admin.ModelAdmin):
    list_display = ('name', 'store', 'description', 'edate')
    class Media:
        js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce/textareas.js')

class LoggingAdmin(admin.ModelAdmin):
    list_display = ('log_type', 'message', 'registry')
    
class KeywordAdmin(admin.ModelAdmin):
    list_display = ('term', 'count', 'registry')
        
class TestMysqlAdmin(admin.ModelAdmin):
    list_display = ('name',)
    # A handy constant for the name of the alternate database.
    using = 'mongodb'

    def save_model(self, request, obj, form, change):
        # Tell Django to save objects to the 'other' database.
        obj.save(using=self.using)

    def delete_model(self, request, obj):
        # Tell Django to delete objects from the 'other' database
        obj.delete(using=self.using)

    def queryset(self, request):
        # Tell Django to look for objects on the 'other' database.
        return super(TestMysqlAdmin, self).queryset(request).using(self.using)

    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        # Tell Django to populate ForeignKey widgets using a query
        # on the 'other' database.
        return super(TestMysqlAdmin, self).formfield_for_foreignkey(db_field, request=request, using=self.using, **kwargs)

    def formfield_for_manytomany(self, db_field, request=None, **kwargs):
        # Tell Django to populate ManyToMany widgets using a query
        # on the 'other' database.
        return super(TestMysqlAdmin, self).formfield_for_manytomany(db_field, request=request, using=self.using, **kwargs)

admin.site.register(Category, CategoryAdmin)
admin.site.register(Store, StoreAdmin)
admin.site.register(FavoriteStore, FavoriteStoreAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(Coupon, CouponAdmin)
admin.site.register(FavoriteCoupon, FavoriteCouponAdmin)
admin.site.register(Order, OrderAdmin)
admin.site.register(SiteUser)
admin.site.register(Recruit, RecruitAdmin)
admin.site.register(Logging, LoggingAdmin)
admin.site.register(Keyword, KeywordAdmin)
